<?php

class Controller_How extends Controller_TemplateNew
{
    public $_section;
    
	public function  before() {
		parent::before();
		$this->db = Database::instance();
		$this->mod = Model::factory('directory');
		$this->section = 'How it works - ';
		$this->_section = 'how';


		$this->template->description = $this->settings['description'];
		$this->template->keywords = $this->settings['keywords'];
		$this->template->linkSettings = $this->settings;
                
                $this->template->header->active='how';
                
	}
    
	public function actionIndex()
	{
		$this->template->title = $this->section.$this->settings['title'];
		$this->template->content = new View('how/index');
                $this->template->content->bottomblock = new View('index/bottomblock');
                $this->template->content->downblock = new View('index/downblock');
                $this->template->content->downblock->formIdea = $this->formIdea;

                //list of catalog
                $signList = $this->mod->getCategories('catalog', 'position');
                $this->template->content->bottomblock->signList = $signList;
                
                //down Block
                $allImages = $this->mod->getImagesByItem('index');
                $bottomBlock = $this->mod->getItem(95, 'index');
                $this->template->content->downblock->bottomBlock = $bottomBlock;
                $bottomBlockCategory = $this->mod->getCategoryByAlias('images-79','images');
                $formConfig = $this->mod->getItemByAlias('9','images');
                $this->template->content->downblock->showForm = ($formConfig['checkbox4']==1) ? true : false;
                $bottomBlockItems = $this->mod->getCategoryItems($bottomBlockCategory['id'],'images','position');
                $tempImg = $this->mod->getImagesByItem('images','position');
                $tempAtt = $this->mod->getAttachmentsByItem('images');
                foreach ($tempImg as $v) {
                    $bottomBlockItems[$v[0]['itemId']]['box4'] = $this->mod->imagePath($v[0],'box4');
                }
                foreach ($tempAtt as $v) {
                    $bottomBlockItems[$v[0]['itemId']]['attacment'] = $this->mod->attachmentPath($v[0]);
                }
                $this->template->content->downblock->items = $bottomBlockItems;
                
                //Most popular and bottom block
                $mostPopular = $this->mod->getItemsCheckbox1('catalog','position');
                foreach ($mostPopular as $k=>$v) {
                    $mostPopularImg = $this->mod->getItemImages($k,'catalog');
                    if (isset($mostPopularImg)) {
                        foreach ($mostPopularImg as $key=>$value) {
                            $mostPopular[$k]['catalogImage'] = $this->mod->imagePath($value,'sign');
                        }
                    }
                }
                $this->template->content->bottomblock->mostPopular = $mostPopular;
                if (isset($allImages[$bottomBlock['id']])) {
                    foreach ($allImages[$bottomBlock['id']] as $key=>$value) {
                        $allImages[$bottomBlock['id']][$key]['imgPath'] = $this->mod->imagePath($value,'box4');
                    }
                }
                
                if (isset($allImages)) {
                    $this->template->content->bottomblock->allImages = $allImages;
                    $this->template->content->downblock->allImages = $allImages;
                }
                
                $this->addScript('/scripts/jquerytools/jquery.rotate.js');
                $this->addScript('/scripts/jquerytools/jquery.tinycarousel.min.js');
//                $this->addStyle('/styles/anythingslider/slider.css');
	}
}